package com.huaguoguo.sso.service.impl;

import com.huaguoguo.base.service.RedisService;
import com.huaguoguo.dao.TbUserMapper;
import com.huaguoguo.entity.User;
import com.huaguoguo.entity.vo.Result;
import com.huaguoguo.enums.ErrorCodeEnum;
import com.huaguoguo.exception.HsException;
import com.huaguoguo.pojo.TbUser;
import com.huaguoguo.sso.feign.RedisServiceApi;
import com.huaguoguo.sso.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 类说明： 登录服务<br/>
 * author:huaguoguo
 * Date: 2019/2/16
 * Time: 20:45
 */
@RestController
@RequestMapping("/sso")
@Slf4j
public class LoginServiceImpl implements LoginService{

    @Autowired
    private RedisServiceApi redisService;

    @Autowired
    private TbUserMapper userMapper;

    @Override
    public Result login(TbUser user) {
        log.info("login： {}",user);
        String errorMessage = "未知错误！";
        // 根据登录名查询用户
        TbUser tbUser = new TbUser();
        tbUser.setUsername(user.getUsername());
        tbUser = userMapper.selectOne(tbUser);
        if (tbUser == null) {
            throw new HsException(ErrorCodeEnum.LOGIN_NO_USER);
        }
        return Result.ok();
    }

    @Override
    public Result currentUser(Long userId) throws Exception {
        boolean aaa = redisService.set("aaa", 123);
        User user = new User();
        user.setId(userId);
        if (userId == 18L) {
            throw new Exception("爆炸吧！！！");
        }
        return Result.ok(user);
    }
}
